package com.hrg.rds.infra.connect.protocol.modbus;

import com.hrg.rds.infra.connect.Properties4x;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;

import java.util.List;

// https://plc4x.apache.org/plc4x/latest/users/protocols/modbus.html
// ModbusTcpConfiguration
@ConfigurationProperties(prefix = "modbus")
@Data
public class ModbusProperties extends Properties4x {
	private boolean enabled = false;
	private List<ModbusProperty> connections;
	@Data
	public static class ModbusProperty extends Properties4x {
		// modbus-tcp:{transport}://{ip-address}:{port}?{options}
		// modbus-tcp:tcp://127.0.0.1:502
		private String host;
		private int port;

		private String extendedParams =
				"request-timeout=5000" +
				"&ping-address=4x00001:BOOL"+
				"&tcp.keep-alive=true" +
				"&tcp.no-delay=true" +
				"&tcp.default-timeout=4000";

		public String getConnId() {
			return String.format("modbus-tcp:tcp://%s:%d?%s", host, port, extendedParams);
		}
	}
}
